$().ready(function() {
	validateRule();


});

$.validator.setDefaults({
	submitHandler : function() {
		save();
	}
});


// 修改
function save() {

	let formData = $('#signupForm').serializeArray();
	let  data = {};
	$.each(formData, function(index, item) {
		data[item.name] = item.value;
	});

	data['id']=$('#UserID').val()
	addFrom(data)

}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			name:{
				required : true
			},
			assetsId : {
				required : true
			},
		}
	})
}



// 修改资源接口
function addFrom(data) {
	return new Promise(function (resolve, reject) {
		$.ajax({
			url: '/jzweb/courses/updateCourseNumber',
			type: 'POST',
			contentType: 'application/json',
			data: JSON.stringify(data),
			success: function(response) {
				// 请求成功时的处理
				if(response.code !== '0') {
					layer.msg(response.msg);
				}else {
					let index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
					parent.layer.close(index);
					parent.reLoad();
					reject(response)
				}

			},
			error: function(xhr, status, error) {
				// 请求失败时的处理
				layer.msg(error);
				resolve(error)
			}
		});
	})

}